package java.hilyb.dbtest;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;

/**
 * User: wlai
 * Date: 12/12/2014
 * Time: 14:52 PM
 */
public class ReadContact extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        testReadNameByPhone();
    }
    //根据电话号码查询姓名（在一个电话打过来时，如果此电话在通讯录中，则显示姓名）
    public void testReadNameByPhone(){
        String phone = "12345678";
        //uri=  content://com.android.contacts/data/phones/filter/#
        Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
        ContentResolver resolver =  this. getContentResolver();
        Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Data.DISPLAY_NAME}, null, null, null); //从raw_contact表中返回display_name
        while(cursor.moveToNext()){
            Log.i("Contacts", "name=" + cursor.getString(0));
        }
    }

}
